package com.jeasonzhao.report.model.simpledb;

import com.jeasonzhao.model.Model;
import com.jeasonzhao.model.ModelException;
import com.jeasonzhao.model.ModelField;
import com.jeasonzhao.model.ModelHelper;
import com.jeasonzhao.report.model.ReportDatabaseConfiguration;

;
@Model
public class DbDatabase
{
    @ModelField
    private String id = null;
    @ModelField
    private String name = null;
    @ModelField
    private String xmlContent = null;
    public ReportDatabaseConfiguration toStandardObject()
        throws ModelException
    {
        ReportDatabaseConfiguration dbc = ModelHelper.getInstance().fromXML(ReportDatabaseConfiguration.class,this.xmlContent);
        if(null == dbc)
        {
            return null;
        }
        else
        {
            dbc.setDatabaseId(this.id);
            dbc.setDatabaseName(this.name);
            return dbc;
        }
    }

    public static DbDatabase fromStandardObject(ReportDatabaseConfiguration dbc)
        throws ModelException
    {
        if(null == dbc)
        {
            return null;
        }
        else
        {
            DbDatabase db = new DbDatabase();
            db.id = dbc.getDatabaseId();
            db.name = dbc.getDatabaseName();
            db.xmlContent = ModelHelper.getInstance().toXML(dbc).toString();
            return db;
        }
    }
}
